#import "ClienteInfoController.h"
#import "ClienteInfo.h"
#import "Vendedor.h"
#import "VendedorInfoController.h"

@interface ClienteInfoController ()
@property (weak, nonatomic) IBOutlet UILabel *nomeFantasiaLabel;
@property (weak, nonatomic) IBOutlet UILabel *cnpjLabel;
@property (weak, nonatomic) IBOutlet UILabel *inscricaoEstadualLabel;
@property (weak, nonatomic) IBOutlet UILabel *vendedorLabel;
@property (weak, nonatomic) IBOutlet UILabel *codigoJolitexLabel;
@property (strong, nonatomic) Vendedor* vendedor;
@end

@implementation ClienteInfoController

@synthesize nomeFantasiaLabel;
@synthesize cnpjLabel;
@synthesize inscricaoEstadualLabel;
@synthesize vendedorLabel;
@synthesize codigoJolitexLabel;
@synthesize vendedor;

-(InfoBase*)getInfo:(NSError **)error {
    InfoBase* info = [super getInfo:error];
    Cliente* cliente = (Cliente*)self.model;
    if (!*error) {
        self.vendedor = [[self.repositoryProvider getRepositoryForClass:[Vendedor class]] getModelById:cliente.vendedorId error:error];
    }
    return info;
}

-(void)setLabels:(InfoBase *)info {
    ClienteInfo* clienteInfo = (ClienteInfo*)info;
    Cliente* cliente = (Cliente*)self.model;
    self.nomeFantasiaLabel.text = clienteInfo.nomeFantasia;
    self.cnpjLabel.text = clienteInfo.cnpj;
    self.inscricaoEstadualLabel.text = clienteInfo.inscricaoEstadual;
    self.codigoJolitexLabel.text = cliente.codigoJolitex;
    self.vendedorLabel.text = self.vendedor.text;
}

-(void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    VendedorInfoController* vendedorInfoController = (VendedorInfoController*)segue.destinationViewController;
    vendedorInfoController.model = self.vendedor;
    vendedorInfoController.repositoryProvider = self.repositoryProvider;
}

@end
